var componentWindowAddressBasePath = componentAddressBasePath+"/dhtmlxWindows_pro";
var themeWindowAddressBasePath = componentWindowAddressBasePath;
if(themeAddr != '1'){ 
	themeWindowAddressBasePath = 'theme/'+themeAddr+'/dhtmlx-style';
}

document.write('<link rel="stylesheet" type="text/css" href="'+themeWindowAddressBasePath+'/dhtmlxwindows.css">');
document.write('<link rel="stylesheet" type="text/css" href="'+themeWindowAddressBasePath+'/skins/dhtmlxwindows_dhx_'+getThemeAddrSuffix()+'.css">');
document.write('<script src="'+componentAddressBasePath+'/dhtmlxcommon.js"></script>');
document.write('<script src="'+componentWindowAddressBasePath+'/dhtmlxwindows.js"></script>');
document.write('<script src="'+componentWindowAddressBasePath+'/dhtmlxcontainer.js"></script>');

var _dhxWins ;

$(function (){
	_dhxWins = createWindowsNormal();
	_dhxWins.setImagePath(themeWindowAddressBasePath+'/imgs/');
});

function setWindowSkin(window,skin){
	window.setSkin(skin || ("dhx_"+ getThemeAddrSuffix() ));
}

function createWindowsNormal(skin){
	var _dhxWinsNew = create_dhtmlXWdinwos_new();
	setWindowSkin(_dhxWinsNew);
	/*
   	_dhxWins.enableAutoViewport(false);
	_dhxWins.attachViewportTo(id);*/
    return _dhxWinsNew;
}


function create_dhtmlXWdinwos_new(){
	return new dhtmlXWindows();
}

function openNewWindowURL(text,url){
	if(validateOpenWindowMaxSize()){
		alert('最多打开'+thisWinsMaxOpenWindowSize()+'个窗口');
	}else{
		var win = createWindowOnly(text);
		win.attachURL(url);
		//start 和loadedoffOpenNewWindowProgress一起使用
		win.progressOn();
		//end 和loadedoffOpenNewWindowProgress一起使用
		loadedoffOpenNewWindowProgress(true);
		return win;
	}
}

function openWindowObj(text,objId){
	var win = createWindowOnly(text);
	win.attachObject(objId,true);
	return win;
}
function openWindowHTMLString(text,attachHTMLString){
	var win = createWindowOnly(text);
	win.attachHTMLString(attachHTMLString);
	win.denyResize();
	win.denyPark();
	
}
function createWindowOnly(text,w,h){
	var win = _dhxWins.createWindow(getNewWindowId(), 10, 10, w?w:halfWidthOfbody(), h?h:halfHeightOfbody());
	win.keepInViewport(true);
	win.center();
	win.setText(text);
	win.setModal(true);
	return win;
}

function validateOpenWindowMaxSize(){
	var p = 0;
    _dhxWins.forEachWindow(function() { p++; });
    if (p > (thisWinsMaxOpenWindowSize()-1)) {
        return true;
    }
    return false;
}

function thisWinsMaxOpenWindowSize(){
	return 6;
}

function halfHeightOfbody(){
	//need jquery
	return $(document.body).height()/3*2;
}

function halfWidthOfbody(){
	//need jquery
	return  $(document.body).width()/3*2;
}

var newWinIdSeq = 0;
function getNewWindowId(){
	return 'win'+(newWinIdSeq++);
}

function loadedoffOpenNewWindowProgress(){
	_dhxWins.attachEvent("onContentLoaded", function(win){win.progressOff();});
}

var myAlertObj;
var waitingWindowObj;
var myConfirmObj;
var myConfirmFun;
function myAlert(text){
	waitingWindowClose();
	myAlertObj = createWindowOnly("",300,150);
	var htmText = '<table style="width:100%;height:100%;">'
				+'<tr><td align="center">'
				+text
				+'</td></tr>'
				+'<tr><td align="center"><button onclick="myAlertObj.close();">&nbsp;&nbsp;确定&nbsp;&nbsp;</button></td></tr>'
				+'</table>';
	myAlertObj.attachHTMLString(htmText);
	myAlertObj.denyResize();
	myAlertObj.denyPark();
	myAlertObj.attachEvent("onClose",function(win){
		return true;
	});
}

function confirmInfo(text , fun){
	myConfirmObj = createWindowOnly("",400,200);
	myConfirmFun = fun;
	var htmText = '<table style="width:100%;height:100%;">'
		+'<tr><td align="center">'
		+text
		+'</td></tr>'
		+'<tr><td align="center"><button onclick="confirmInfo_middelFunction(\'ok\')">&nbsp;&nbsp;确定&nbsp;&nbsp;</button>&nbsp;&nbsp;&nbsp;&nbsp;'
		+'<button onclick="confirmInfo_middelFunction(\'no\')">&nbsp;&nbsp;取消&nbsp;&nbsp;</button></td></tr>'
		+'</table>';
	myConfirmObj.attachHTMLString(htmText);
	myConfirmObj.denyResize();
	myConfirmObj.denyPark();
	myConfirmObj.attachEvent("onClose",function(win){
		fun('no');
		return true;
	});
}

function confirmInfo_middelFunction(text){
	myConfirmFun(text);
	myConfirmObj.close();
}

function waitingWindow(){
	waitingWindowObj = createWindowOnly("",256,52);
	waitingWindowObj.attachHTMLString('<img height="51" width="243" id="loadingImg" src="theme/images/progress.gif" />');
	waitingWindowObj.denyResize();
	waitingWindowObj.hideHeader();
	return waitingWindowObj;
}
function waitingWindowClose(){
	if(waitingWindowObj){
		waitingWindowObj.close();
		waitingWindowObj = undefined;
	}
}

